package com.trkj.service.impt;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Scanner;
@Slf4j
@Aspect
@Component
public class phoneA {
    @Around("execution(* com.trkj.service.impt.Phone3.makeCall(String)) && args(number)")
    public void logMakeCall(ProceedingJoinPoint joinPoint, String number) throws Throwable {
        long startTime = System.currentTimeMillis(); // 记录通话开始时间
        log.debug("来电显示：" + number);
        // 调用原始方法
        joinPoint.proceed(new Object[]{number});

        long endTime = System.currentTimeMillis(); // 记录通话结束时间
        long duration = endTime - startTime; // 计算通话时长
        log.debug("通话时长：" + duration + "ms");
    }

    @Around("execution(* com.trkj.service.impt.Phone3.sendMessage(*,*))")
    public void logSendMessage(ProceedingJoinPoint joinPoint) throws Throwable {
        Scanner scanner = new Scanner(System.in);
        log.debug("请输入收信号码：");
        String receiver = scanner.nextLine();

        log.debug("请输入信息内容：");
        String content = scanner.nextLine();

        // 调用原始方法
        joinPoint.proceed(new Object[]{receiver, content});
    }
}
